package com.pactera.madp.cp.controller.sidebar.agent;

import com.pactera.madp.cp.api.dto.WechatMpRecMsgDto;
import com.pactera.madp.cp.service.WechatComponentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wx-mp")
@Api(value = "wx-mp", tags = "授权事件接收验证")
public class WechatMpCalBkController {

    @Resource
    private WechatComponentService wechatComponentService;

    @PostMapping(value = "/callback",consumes = "text/xml;charset=utf-8")
    @ApiOperation(value = "授权事件接收回调")
    public String callback(@RequestBody WechatMpRecMsgDto dto, String msg_signature, String timestamp, String nonce){
        String encrypt = dto.getEncrypt();
        wechatComponentService.saveTicketToRedis(encrypt);
        log.info("授权事件消息接收：{},{},{},{}",dto,msg_signature,timestamp,nonce);
        return "success";
    }

}
